package work.jame.blog.controller;


import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import work.jame.blog.framework.limit.RequestLimit;
import work.jame.blog.framework.result.Result;
import work.jame.blog.service.UserArticleLikeService;

import java.util.concurrent.TimeUnit;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author Jame
 * @since 2023-05-18
 */
@RestController
@RequestMapping("/userArticleLike")
public class UserArticleLikeController {


    @Autowired
    private UserArticleLikeService userArticleLikeService;


    @ApiOperation("点赞文章")
    @GetMapping("/likeArticle")
    @RequestLimit(value = 10, timeUnit = TimeUnit.MINUTES)
    public Result<?> likeArticle(@RequestParam("articleId") Long articleId) {
        if (userArticleLikeService.likeArticle(articleId)) {
            return Result.succeedMessage("点赞成功");
        }
        return Result.fail("点赞失败");
    }

    @ApiOperation("取消点赞文章")
    @GetMapping("/cancelLikeArticle")
    @RequestLimit(value = 10, timeUnit = TimeUnit.MINUTES)
    public Result<?> cancelLikeArticle(@RequestParam("articleId") Long articleId) {
        if (userArticleLikeService.cancelLikeArticle(articleId)) {
            return Result.succeedMessage("已取消点赞");
        }
        return Result.fail("取消点赞失败");
    }


}
